package com.gnerv.sylvanas.framework.common.model.sse;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.gnerv.sylvanas.framework.common.tools.DateTimeTools;
import lombok.Data;

/**
 * @author Gnerv LiGen
 */
@Data
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonPropertyOrder({"topic", "data", "timestamp"})
public class SseResult<T> {

    private String topic;
    private T data;
    private long timestamp;

    private SseResult() {}

    public static <T> SseResult<T> build(String topic, T data) {
        return build(topic, data, DateTimeTools.currentTimeMillis());
    }

    public static <T> SseResult<T> build(String topic, T data, long timestamp) {
        SseResult<T> sseResult = new SseResult<>();
        sseResult.setTopic(topic);
        sseResult.setData(data);
        sseResult.setTimestamp(timestamp);
        return sseResult;
    }

}
